{extend name="../../admin/view/main"}

{block name="style"}{include file='eduenroll/form-style'}{/block}

{block name='content'}
<style>
    .upload-image-box {
        width: 130px;
        height: 110px;
        border: 1px solid rgba(125, 125, 125, .1);
        background-size: cover;
    }
    .upload-file-box {
        width: 80px;
        height: 50px;
        border: 1px solid rgba(125, 125, 125, .1);
        background-size: cover;
    }


</style>
<div id="infoFormEditor" class="layui-clear nowrap padding-bottom-30">
    <div class="layui-card news-right">
        <div class="layui-card-body">
            <!--<form onsubmit="return false" data-auto="true" action="{:request()->url()}" method="post" class='layui-form layui-card' autocomplete="off">-->
            <form class="layui-form padding-20" role="form" name="infoForm" onsubmit="return false">

                <label class="layui-form-item relative block">
                    <span class="color-green" required="">姓名</span>
                    <input maxlength="10" disabled type="text" placeholder="请输入姓名" name="name" value="{$enroll.name}" class="layui-input" />
                </label>
                <label class="layui-form-item relative block">
                    <span class="color-green">分数</span>
                    <input maxlength="256" value="{$enroll.score}" required placeholder="请在这里输入分数" name='score' class="layui-input">
                </label>
                <label class="layui-form-item relative block">
                    <span class="color-green" required>是否合格</span>
                    <div>
                        {if $enroll.is_pass eq 1}
                            <input type="radio" name="is_pass" value="1" lay-filter="PassRadio" checked title="合格">
                            <input type="radio" name="is_pass" value="2" lay-filter="PassRadio" title="不合格" >
                        {else}
                            <input type="radio" name="is_pass" value="1" lay-filter="PassRadio" title="合格">
                            <input type="radio" name="is_pass" value="2" lay-filter="PassRadio" checked title="不合格" >
                        {/if}
                    </div>
                </label>
                <div class="layui-form-item text-center padding-top-30">
                    <input ng-model="x.read_num" type="hidden">
                    <input type="hidden" name="id" ng-model="item.id" value="{$enroll.id}" />
                    <button ng-click="submit()" type="button" class="layui-btn">保存信息</button>
                </div>
            </form>
        </div>
    </div>
</div>
<div name="annex-template" style="display: none;">
    <div class="item" file="__URL__">
        <a target="_blank" href="__URL__">__TITLE__</a>
        <span class="font-s20 fa fa-trash"></span>
    </div>
</div>
{/block}


{block name='script'}
<script>window.form.render()</script>
<script>


        require(['angular', 'ckeditor'], function () {

            /*layui.use(['form'], function () {
                var form = layui.form;
            });*/

        var editor;
        var $form = $('form[name="infoForm"]');
        var $vali = $form.vali().data('validate');

        var app = angular.module("infoFormEditor", []).run(callback);
        angular.bootstrap(document.getElementById(app.name), [app.name]);

        function callback($rootScope) {
            $rootScope.list = [];
            $rootScope.item = {};
            $.form.load('{:request()->url()}', {output: 'json'}, 'get', function (ret) {
                console.log(typeof ret);
                console.log(ret);
                return $rootScope.$apply(function () {
                    apply(ret.data || {});
                }), false;
            });
                function apply(qiye) {
                    if(qiye.id==undefined) qiye = {
                        name: '', phone: '', contacts: '',intro:'',
                        addr: '', logo: '__ROOT__/static/theme/img/image.png',annex:  '__ROOT__/static/theme/img/image.png',
                    };
                    $rootScope.item = qiye;
                    $('.layui-card-body.layui-hide').removeClass('layui-hide');
                    $rootScope.item.style = "background-image:url('" + $rootScope.item.logo + "')";
                }
            $rootScope.setItemValue = function (name, value) {
                $rootScope.item[name] = value;
                $rootScope.item.style = "background-image:url('" + $rootScope.item.logo + "')";
            };

            $rootScope.setItemValuel = function (name, value) {
                $rootScope.item[name] = value;
                $rootScope.item.style = "background-file:url('" + $rootScope.item.annex + "')";

            };

            $rootScope.upItem = function (index, $event) {
                $event.stopPropagation();
                var tmp = [], cur = $rootScope.list[index];
                if (index < 1) return false;
                for (var i in $rootScope.list) {
                    (parseInt(i) === parseInt(index) - 1) && tmp.push(cur);
                    (parseInt(i) !== parseInt(index)) && tmp.push($rootScope.list[i]);
                }
                apply(tmp);
            };
            $rootScope.dnItem = function (index, $event) {
                $event.stopPropagation();
                var tmp = [], cur = $rootScope.list[index];
                if (index > $rootScope.list.length - 2) return false;
                for (var i in $rootScope.list) {
                    (parseInt(i) !== parseInt(index)) && tmp.push($rootScope.list[i]);
                    (parseInt(i) === parseInt(index) + 1) && tmp.push(cur);
                }
                apply(tmp);
            };
            $rootScope.delItem = function (index, $event) {
                $event.stopPropagation();
                var list = $rootScope.list, temp = [];
                for (var i in list) (parseInt(i) !== parseInt(index)) && temp.push(list[i]);
                apply(temp);
            };
            $rootScope.submit = function () {
                $vali.checkAllInput();
                if ($form.find('.validate-error').size() > 0) {
                    return $.msg.tips('表单验证不成功，请输入需要的内容！');
                }
                var data = {
                    id: $("input[name='id']").val(),
                    score: $("input[name='score']").val(),
                    is_pass: $("input[name='is_pass']").val(),
                };
                $.form.load('{:request()->url()}', {data: data}, "post");
            };
        }

    });
        layui.form.on('radio(PassRadio)', function(data){
            $("input[name=is_pass]").val(data.value);
        });
</script>




{/block}